package com.xukehong.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;


/**
 * @Author: xkh
 * @Date: 2019/11/1 15:01
 * @Version 1.0
 */
@Configuration
public class RedisListenerConfig {

    @Bean
    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory){
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        //灵活配置，针对每个库的失效key做处理
        //container.addMessageListener(                                                      new RedisExpiredListener(), new PatternTopic("__keyevent@0__:expired"));
        return container;
    }
}